var a =[]
a[1] = 1
a[2] = 1
for (let i = 3; i <= 20; i++) {
    a[i]= a[i-1]+a[i-2]
    
}
// console.log(a[20]);


// var num = [1,2,3,4,5,6]
// num.splice(2,3)
// console.log(num);


var arr = [1,24,23,5,6,2]
// arr.sort((a,b)=>(a-b))
// console.log(arr);

function swap(x,y){
    var temp = arr[x] 
    arr[x] = arr[y]
    arr[y] = temp
}
// for (let j = arr.length-1; j >0; j--) {

//     for (let index = 0; index < j; index++) {
//         if(arr[index]>arr[index+1])swap(index,index+1)
        
//     }
// }

console.log(arr);

// 快排
function quick(arr){
    if(arr.length<=1)return arr
    var left = []
    var right = []
    // 找到基准
    var pivotIndex = ~~(arr.length/2)
    var pivot = arr.splice(pivotIndex,1)[0]
    
    for(let i = 0;i<arr.length;i++)
    {
        if(arr[i]<pivot) left.push(arr[i])
        if(arr[i]>= pivot) right.push(arr[i])
    }
    return quick(left).concat(pivot,quick(right))
}
console.log(quick([1, 23, 4, 5, 7, 0, 99, -1]));